// 存放列表相关操作
let db = require('../db/service_index')



exports.all = (req, res) => { //获取T_Service表全部数据
    var sql = 'select * from T_Service'
    db.query(sql, [req.query.id, req.query.order, req.query.time, req.query.address, req.query.phone, req.query.name, req.query.status], (err, data) => {
        if (err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.add = (req, res) => { //向T_Service表添加数据
    var sql = 'INSERT INTO T_Service( `order`,`time`,`address`,`phone`,`name`,`status`) VALUES(?,?,?,?,?,1);'
    db.query(sql, [req.body.order, req.body.time, req.body.address, req.body.phone, req.body.name, req.body.status], (err, data) => {
        if (err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}

exports.update = (req, res) => { //通过id更新数据
    var id = parseInt(req.params.id);
    console.log(id);
    var sql = 'update T_Service set `order` = ?, `time` = ?, `address` = ?, `phone` = ? , `name` = ?, `status` = ? where `id` = ?'
    db.query(sql, [req.body.order, req.body.time, req.body.address, req.body.phone, req.body.name, req.body.status, id], (err, data) => {
        if (err) {
            return res.send('错误：' + err.message)
        }
        res.send(data)
    })
}